using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VSCHICHTP
    {
        public DataRow Convert2SCHICHTP(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QuerySCHICHTP(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["AKSMANDANT"] = " ".PadRight(2 ); 
         dwReturn["AKSPKSTKRS"] = " ".PadRight(2 ); 
         dwReturn["AKSPKST"] = " ".PadRight(4 ); 
         dwReturn["AKSMTYP"] = " ".PadRight(8 ); 
         dwReturn["AKSNRKRS"] = " ".PadRight(2 ); 
         dwReturn["AKSLFDNR"] = " ".PadRight(4 ); 
         dwReturn["AKSPOS"] = " ".PadRight(2 ); 
         dwReturn["AKSPERSNR"] = " ".PadRight(0 ); 
         dwReturn["AKSJJJJ"] = " ".PadRight(0 ); 
         dwReturn["AKSMM"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN1"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN2"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN3"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN4"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN5"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN6"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN7"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN8"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN9"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN10"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN11"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN12"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN13"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN14"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN15"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN16"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN17"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN18"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN19"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN20"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN21"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN22"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN23"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN24"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN25"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN26"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN27"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN28"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN29"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN30"] = " ".PadRight(0 ); 
         dwReturn["AKSSTUNDEN31"] = " ".PadRight(0 ); 
         dwReturn["AKSWERK"] = " ".PadRight(3 ); 
         dwReturn["AKSABT"] = " ".PadRight(3 ); 
         dwReturn["AKSAENDZL"] = " ".PadRight(0 ); 
         dwReturn["AKSAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["AKSAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["AKSNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["AKSNEUDAT"] = " ".PadRight(0 ); 
         dwReturn["AKSFILLER"] = " ".PadRight(14 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapSCHICHTP(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveSCHICHTP(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QuerySCHICHTP(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapSCHICHTP(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertSCHICHTP(dwLocal, ITXDBVERSION);
            }
            UpdateSCHICHTP(dwLocal);
        }
        public void InsertSCHICHTP(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO SCHICHTP(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QuerySCHICHTP(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM SCHICHTP WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM SCHICHTP  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "SCHICHTP";
            Return = Result;
            return Return;
        }
        public void DeleteSCHICHTP(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM SCHICHTP   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateSCHICHTP(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE SCHICHTP SET "
                    +"AKSMANDANT= :AKSMANDANT,"
                    +"AKSPKSTKRS= :AKSPKSTKRS,"
                    +"AKSPKST= :AKSPKST,"
                    +"AKSMTYP= :AKSMTYP,"
                    +"AKSNRKRS= :AKSNRKRS,"
                    +"AKSLFDNR= :AKSLFDNR,"
                    +"AKSPOS= :AKSPOS,"
                    +"AKSPERSNR= :AKSPERSNR,"
                    +"AKSJJJJ= :AKSJJJJ,"
                    +"AKSMM= :AKSMM,"
                    +"AKSSTUNDEN1= :AKSSTUNDEN1,"
                    +"AKSSTUNDEN2= :AKSSTUNDEN2,"
                    +"AKSSTUNDEN3= :AKSSTUNDEN3,"
                    +"AKSSTUNDEN4= :AKSSTUNDEN4,"
                    +"AKSSTUNDEN5= :AKSSTUNDEN5,"
                    +"AKSSTUNDEN6= :AKSSTUNDEN6,"
                    +"AKSSTUNDEN7= :AKSSTUNDEN7,"
                    +"AKSSTUNDEN8= :AKSSTUNDEN8,"
                    +"AKSSTUNDEN9= :AKSSTUNDEN9,"
                    +"AKSSTUNDEN10= :AKSSTUNDEN10,"
                    +"AKSSTUNDEN11= :AKSSTUNDEN11,"
                    +"AKSSTUNDEN12= :AKSSTUNDEN12,"
                    +"AKSSTUNDEN13= :AKSSTUNDEN13,"
                    +"AKSSTUNDEN14= :AKSSTUNDEN14,"
                    +"AKSSTUNDEN15= :AKSSTUNDEN15,"
                    +"AKSSTUNDEN16= :AKSSTUNDEN16,"
                    +"AKSSTUNDEN17= :AKSSTUNDEN17,"
                    +"AKSSTUNDEN18= :AKSSTUNDEN18,"
                    +"AKSSTUNDEN19= :AKSSTUNDEN19,"
                    +"AKSSTUNDEN20= :AKSSTUNDEN20,"
                    +"AKSSTUNDEN21= :AKSSTUNDEN21,"
                    +"AKSSTUNDEN22= :AKSSTUNDEN22,"
                    +"AKSSTUNDEN23= :AKSSTUNDEN23,"
                    +"AKSSTUNDEN24= :AKSSTUNDEN24,"
                    +"AKSSTUNDEN25= :AKSSTUNDEN25,"
                    +"AKSSTUNDEN26= :AKSSTUNDEN26,"
                    +"AKSSTUNDEN27= :AKSSTUNDEN27,"
                    +"AKSSTUNDEN28= :AKSSTUNDEN28,"
                    +"AKSSTUNDEN29= :AKSSTUNDEN29,"
                    +"AKSSTUNDEN30= :AKSSTUNDEN30,"
                    +"AKSSTUNDEN31= :AKSSTUNDEN31,"
                    +"AKSWERK= :AKSWERK,"
                    +"AKSABT= :AKSABT,"
                    +"AKSAENDZL= :AKSAENDZL,"
                    +"AKSAENDBEN= :AKSAENDBEN,"
                    +"AKSAENDDAT= :AKSAENDDAT,"
                    +"AKSNEUBEN= :AKSNEUBEN,"
                    +"AKSNEUDAT= :AKSNEUDAT,"
                    +"AKSFILLER= :AKSFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("AKSMANDANT", OracleType.NVarChar).Value = dwData["AKSMANDANT"].ToString(); 
          or1.Parameters.Add("AKSPKSTKRS", OracleType.NVarChar).Value = dwData["AKSPKSTKRS"].ToString(); 
          or1.Parameters.Add("AKSPKST", OracleType.NVarChar).Value = dwData["AKSPKST"].ToString(); 
          or1.Parameters.Add("AKSMTYP", OracleType.NVarChar).Value = dwData["AKSMTYP"].ToString(); 
          or1.Parameters.Add("AKSNRKRS", OracleType.NVarChar).Value = dwData["AKSNRKRS"].ToString(); 
          or1.Parameters.Add("AKSLFDNR", OracleType.NVarChar).Value = dwData["AKSLFDNR"].ToString(); 
          or1.Parameters.Add("AKSPOS", OracleType.NVarChar).Value = dwData["AKSPOS"].ToString(); 
          or1.Parameters.Add("AKSPERSNR", OracleType.NVarChar).Value = dwData["AKSPERSNR"].ToString(); 
          or1.Parameters.Add("AKSJJJJ", OracleType.NVarChar).Value = dwData["AKSJJJJ"].ToString(); 
          or1.Parameters.Add("AKSMM", OracleType.NVarChar).Value = dwData["AKSMM"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN1", OracleType.NVarChar).Value = dwData["AKSSTUNDEN1"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN2", OracleType.NVarChar).Value = dwData["AKSSTUNDEN2"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN3", OracleType.NVarChar).Value = dwData["AKSSTUNDEN3"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN4", OracleType.NVarChar).Value = dwData["AKSSTUNDEN4"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN5", OracleType.NVarChar).Value = dwData["AKSSTUNDEN5"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN6", OracleType.NVarChar).Value = dwData["AKSSTUNDEN6"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN7", OracleType.NVarChar).Value = dwData["AKSSTUNDEN7"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN8", OracleType.NVarChar).Value = dwData["AKSSTUNDEN8"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN9", OracleType.NVarChar).Value = dwData["AKSSTUNDEN9"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN10", OracleType.NVarChar).Value = dwData["AKSSTUNDEN10"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN11", OracleType.NVarChar).Value = dwData["AKSSTUNDEN11"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN12", OracleType.NVarChar).Value = dwData["AKSSTUNDEN12"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN13", OracleType.NVarChar).Value = dwData["AKSSTUNDEN13"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN14", OracleType.NVarChar).Value = dwData["AKSSTUNDEN14"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN15", OracleType.NVarChar).Value = dwData["AKSSTUNDEN15"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN16", OracleType.NVarChar).Value = dwData["AKSSTUNDEN16"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN17", OracleType.NVarChar).Value = dwData["AKSSTUNDEN17"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN18", OracleType.NVarChar).Value = dwData["AKSSTUNDEN18"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN19", OracleType.NVarChar).Value = dwData["AKSSTUNDEN19"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN20", OracleType.NVarChar).Value = dwData["AKSSTUNDEN20"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN21", OracleType.NVarChar).Value = dwData["AKSSTUNDEN21"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN22", OracleType.NVarChar).Value = dwData["AKSSTUNDEN22"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN23", OracleType.NVarChar).Value = dwData["AKSSTUNDEN23"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN24", OracleType.NVarChar).Value = dwData["AKSSTUNDEN24"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN25", OracleType.NVarChar).Value = dwData["AKSSTUNDEN25"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN26", OracleType.NVarChar).Value = dwData["AKSSTUNDEN26"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN27", OracleType.NVarChar).Value = dwData["AKSSTUNDEN27"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN28", OracleType.NVarChar).Value = dwData["AKSSTUNDEN28"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN29", OracleType.NVarChar).Value = dwData["AKSSTUNDEN29"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN30", OracleType.NVarChar).Value = dwData["AKSSTUNDEN30"].ToString(); 
          or1.Parameters.Add("AKSSTUNDEN31", OracleType.NVarChar).Value = dwData["AKSSTUNDEN31"].ToString(); 
          or1.Parameters.Add("AKSWERK", OracleType.NVarChar).Value = dwData["AKSWERK"].ToString(); 
          or1.Parameters.Add("AKSABT", OracleType.NVarChar).Value = dwData["AKSABT"].ToString(); 
          or1.Parameters.Add("AKSAENDZL", OracleType.NVarChar).Value = dwData["AKSAENDZL"].ToString(); 
          or1.Parameters.Add("AKSAENDBEN", OracleType.NVarChar).Value = dwData["AKSAENDBEN"].ToString(); 
          or1.Parameters.Add("AKSAENDDAT", OracleType.NVarChar).Value = dwData["AKSAENDDAT"].ToString(); 
          or1.Parameters.Add("AKSNEUBEN", OracleType.NVarChar).Value = dwData["AKSNEUBEN"].ToString(); 
          or1.Parameters.Add("AKSNEUDAT", OracleType.NVarChar).Value = dwData["AKSNEUDAT"].ToString(); 
          or1.Parameters.Add("AKSFILLER", OracleType.NVarChar).Value = dwData["AKSFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
